﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace CSPGetFieldList
{
    class Program
    {
        static void Main(string[] args)
        {
            String mensagemUsing = string.Format(@"CPSGetFieldList :: vers 1.0.0

Tem que definir os parâmetros para seu correcto funcionamento.

c:/>CSPGetFieldList '<http://website>' '<list's name>'");



            if (args.Length < 2)
            {
                Console.WriteLine(mensagemUsing);
            }
            else
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    Console.WriteLine("Field to List: [{0}]", args[1]);
                    using (SPSite site = new SPSite(args[0]))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            SPList lista = web.Lists[args[1]];
                            Console.WriteLine("Name\t\t Type\t\t ReadOnly\n----------------------------------------->>");

                            foreach (SPField field in lista.Fields.OfType<SPField>().Where(f => !f.ReadOnlyField))
                            {
                                Console.WriteLine("{0}\t\t {1}\t\t {2}"
                                    , field.Title
                                    , field.Type
                                    , field.ReadOnlyField);
                            }
                        }
                    }
                    Console.WriteLine("OK");
                });
            }
        }
    }
}
